﻿using SiliconSelect.BLL;
using SiliconSelect.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SiliconSelect.Views.UserOperatorDialog
{
    /// <summary>
    /// AlarmSettingDialog.xaml 的交互逻辑
    /// </summary>
    public partial class AlarmSettingDialog : Window
    {
        AlarmSettingViewModel viewModel = new AlarmSettingViewModel();
        public AlarmSettingDialog()
        {
            InitializeComponent();
            DataContext = viewModel;
        }

        // 界面上点击了保存按钮,就是将viewModel里面的结果保存到数据库里面去.
        private void BtnSaveClick(object sender, RoutedEventArgs e)
        {
            DataResult result = LocalDataAccess.SaveAlarmSetting(viewModel.AlarmSettingList!.ToList());
            if (result.State)
            {
                // 1. 保存成功
                MessageBox.Show("保存成功!", "操作提示框", MessageBoxButton.OK, MessageBoxImage.Information);
                viewModel.RefreshDataTask();
            }
            else
            {
                // 2. 保存失败
                MessageBox.Show($"保存失败:{result.Message}", "数据库操作失败提示框", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
